<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>流浪动物管理系统</title>
    <link type="text/css" rel="stylesheet" href="css/style.css"/>
    <link type="text/css" rel="stylesheet" href="css/public.css"/>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <div class="quan">
        <div id="div1">
            <img src="images/beijing2.jpg">
        </div>

    <!--头部-->
    <header class="publicHeader">
        <h1>流浪动物管理系统</h1>
        <div class="publicHeaderR">
            <p><span>下午好！</span><span style="color: #fff21b"> 管理员</span> , 欢迎你！</p>
            <a href="jsp/logout.do">退出</a>
        </div>
    </header>
    <!--时间-->
    <section class="publicTime">
        <span id="time">2015年1月1日 11:11  星期一</span>
        <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
    </section>
    <!--主体内容-->
    <section class="publicMian ">
        <div class="left">
            <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
            <nav>
                <ul class="list">
                    <li><a href="animal.html">动物管理</a></li>
                    <li><a href="adoptive.html">领养者管理</a></li>
                    <li><a href="user.html">用户管理</a></li>
                    <li><a href="update_pass.html">密码修改</a></li>
                    <li><a href="#" @click="logout">退出系统</a></li>
                </ul>
            </nav>
        </div>
        <input type="hidden" id="path" name="path" value="/SMBMS"/>
        <input type="hidden" id="referer" name="referer" value="http://localhost:8080jsp/bill.do?method=query"/>

        <div class="right">
            <div class="location">
                <strong>你现在所在的位置是:</strong>
                <span>领养者管理页面</span>
            </div>
            <div class="search">
                <span>领养者编码：</span>
                <input name="queryProCode" type="text" v-model="adoCode">
                <span>领养者名称：</span>
                <input name="queryProName" type="text" v-model="adoName">
                <input value="查 询" type="submit" id="searchbutton" @click="searchAdoptive">
                <a href="adoptive_save.html">添加领养者</a>
            </div>
            <!--供应商操作表格-->
            <table class="providerTable" cellpadding="0" cellspacing="0">
                <tr class="firstTr">
                    <th width="10%">领养者编码</th>
                    <th width="10%">领养者名称</th>
                    <th width="10%">领养者电话</th>
                    <th width="20%">领养者地址</th>
                    <th width="10%">领养者性别</th>
                    <th width="10%">领养的宠物</th>
                    <th width="30%">操作</th>
                </tr>

                <tr v-for="a in adoptives">
                    <td>
                        <span>{{a.adoCode}}</span>
                    </td>
                    <td>
                        <span>{{a.adoName}}</span>
                    </td>
                    <td>
                        <span>{{a.phone}}</span>
                    </td>
                    <td>
                        <span>{{a.address}}</span>
                    </td>
                    <td>
                        <span>{{a.gender == 1 ? '女' : '男'}}</span>
                    </td>
                    <td>
                        <span>{{a.pet}}</span>
                    </td>
                    <td>
                        <span>
                            <a class="viewProvider" href="#" @click="showAdoptive(a)">
                            <img src="images/read2.png" alt="查看" title="查看"/>
                            </a>
                        </span>
                        <span>
                            <a class="modifyProvider" href="#" @click="updateAdoptive(a)">
                                <img src="images/xiugai2.png" alt="修改" title="修改"/>
                            </a>
                        </span>
                        <span>
                            <a class="deleteProvider" href="#" @click="deleteAdoptive(a.id)">
                                <img src="images/schu2.png" alt="删除" title="删除"/>
                            </a>
                        </span>
                    </td>
                </tr>
            </table>
            <div style="margin: auto;text-align: center">
                <el-pagination
                        background
                        page-size="10"
                        layout="prev, pager, next"
                        :total="result.total" @current-change="loadAllAdoptiveData">
                </el-pagination>
            </div>


        </div>
    </section>

    <!--点击删除按钮后弹出的页面-->
    <div class="zhezhao"></div>
    <div class="remove" id="removeProv">
        <div class="removerChid">
            <h2>提示</h2>
            <div class="removeMain">
                <p>你确定要删除该领养者吗？</p>
                <a href="#" id="yes">确定</a>
                <a href="#" id="no">取消</a>
            </div>
        </div>
    </div>
    <footer class="footer">
        版权归汪汪队立大功
    </footer>
</div>
</div>
<script type="text/javascript" src="js/time.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="calendar/WdatePicker.js"></script>
</body>
</html>
<script src="js/vue.min.js"></script>
<script src="js/axios.min.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                adoptives: [],
                adoCode: '',
                adoName: '',
                result:'',
            }
        },
        methods: {
            // 加载所有领养者信息
            loadAllAdoptiveData(page) {
                axios({
                    method: 'get',
                    url: 'adoptive/find',
                    params:{
                        page
                    }
                }).then(resp => {
                    this.result = resp.data
                    // 集合
                    this.adoptives = this.result.list
                })
            },
            //     删除领养者的函数
            deleteAdoptive(aid) {

                // 引入饿了么
                this.$confirm('此操作将永久删除该领养者, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios({
                        url: 'adoptive/delete',
                        params: {
                            id: aid
                        }
                    }).then(resp => {
                        if (resp.data === 1) {
                            // 刷新
                            this.loadAllAdoptiveData()
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            // 搜索用户
            searchAdoptive() {
                axios({
                    url: 'adoptive/find_name',
                    params: {

                        adoCode: this.adoCode,
                        adoName: this.adoName,
                        page: 1,
                        size: 10

                    }
                }).then(resp => {
                    this.result = resp.data
                    this.adoptives = this.result.list

                })
            },
            //     查看用户
            showAdoptive(adoptive) {
                //         将adoptive保存下来
                let key = 'ADOPTIVE'
                let value = JSON.stringify(adoptive)
                sessionStorage.setItem(key, value)
                //     跳转到显示页面中
                location.href = 'adoptive_show.html'
            },
            updateAdoptive(adoptive) {
                let key = 'ADOPTIVE'
                let value = JSON.stringify(adoptive)
                sessionStorage.setItem(key, value)
                //     跳转到显示页面中
                location.href = 'adoptive_update.html'
            },
            logout(){


                this.$confirm('此操作将退出, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(resp => {
                    axios({
                        url:'adoptive/logout'
                    }).then(resp=>{
                        location.href='login.html'
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消退出'
                    });
                });
            }


        },
        created() {
            this.loadAllAdoptiveData()
        }
    })
</script>